//
//  MyCacheViewController.m
//  CWRD
//
//  Created by lanou on 15/9/17.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "MyCacheViewController.h"
#import "MyCacheByHandTableViewCell.h"
#import "MyCacheAutomaticTableViewCell.h"
@interface MyCacheViewController ()<UITableViewDataSource,UITableViewDelegate>
@property(nonatomic,strong)HMSegmentedControl *segment;
@property(nonatomic,strong)UITableView *cacheByHand;
@property(nonatomic,strong)UITableView *cacheAutomatic;
@end

@implementation MyCacheViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"我的缓存";
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor cyanColor],NSForegroundColorAttributeName, nil]];
    
    self.segment = [[HMSegmentedControl alloc] initWithSectionTitles:@[@"手动缓存",@"日报自动缓存"]];
    
    self.segment.selectedIndex = 0;
    [self.segment setFrame:CGRectMake(0, 0, kWidth, 60)];
    self.segment.selectionIndicatorColor = [UIColor cyanColor];
    self.segment.selectionIndicatorHeight = 2;
    self.segment.textColor = [UIColor cyanColor];
    self.segment.backgroundColor = [UIColor blackColor];
    [self.segment addTarget:self action:@selector(actionSegmentControl:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:self.segment];
    [self addView];
    
    [self.cacheByHand registerClass:[MyCacheByHandTableViewCell class] forCellReuseIdentifier:@"hand"];
    [self.cacheAutomatic registerClass:[MyCacheAutomaticTableViewCell class] forCellReuseIdentifier:@"automatic"];
}

- (void)addView{
    self.cacheByHand = [[UITableView alloc] initWithFrame:CGRectMake(0, 60, kWidth, kHeight - 153) style:UITableViewStylePlain];
    self.cacheByHand.hidden = NO;
    self.cacheByHand.backgroundColor = [UIColor whiteColor];
    self.cacheByHand.delegate = self;
    self.cacheByHand.dataSource = self;
    self.cacheByHand.tag = 5000;
    [self.view addSubview:self.cacheByHand];
    self.cacheByHand.backgroundColor = [UIColor brownColor];
    
    
    self.cacheAutomatic = [[UITableView alloc] initWithFrame:CGRectMake(0, 60, kWidth, kHeight -  153) style:UITableViewStylePlain];
    self.cacheAutomatic.backgroundColor = [UIColor whiteColor];
    self.cacheAutomatic.hidden = YES;
    self.cacheAutomatic.delegate = self;
    self.cacheAutomatic.dataSource = self;
    self.cacheAutomatic.tag = 5001;
    [self.view addSubview:self.cacheAutomatic];
    self.cacheAutomatic.backgroundColor = [UIColor cyanColor];
    
}

- (void)actionSegmentControl:(HMSegmentedControl *)segmentControl{
    switch (segmentControl.selectedIndex) {
        case 0:
            self.cacheAutomatic.hidden = YES;
            self.cacheByHand.hidden = NO;
            break;
        case 1:
            self.cacheByHand.hidden = YES;
            self.cacheAutomatic.hidden = NO;
            break;
        default:
            break;
    }
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (tableView.tag == 5000) {
        MyCacheByHandTableViewCell *handCell = [self.cacheByHand dequeueReusableCellWithIdentifier:@"hand" forIndexPath:indexPath];
        return handCell;
    }else{
        MyCacheAutomaticTableViewCell *automaticCell = [self.cacheAutomatic dequeueReusableCellWithIdentifier:@"automatic" forIndexPath:indexPath];
        return automaticCell;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 300;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
